﻿package com.eitb.botones {
	import flash.geom.*;
	import flash.text.*;
	import flash.events.*;
	import flash.display.*;
	import com.eitb.events.ScrollEvent;
	public class ScrollRojo extends Boton {
		private var MIN_Y:Number;
		private var MAX_Y:Number;
		private var mover:Boolean;
		public function ScrollRojo():void {
			MIN_Y = 0;
			MAX_Y = this.scroll.height - this.scroll.boton.height;
			this.addEventListener(MouseEvent.MOUSE_DOWN,downBoton);
			this.addEventListener(MouseEvent.MOUSE_UP,upBoton);
			this.addEventListener(MouseEvent.MOUSE_OUT,outBoton);			
			this.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse);
			this.mover = false;
		}
		
		private function moveMouse(event:MouseEvent):void {
			if (this.mover) {
				this.scroll.boton.y = this.scroll.mouseY;
				if (this.scroll.boton.y < MIN_Y) {
					this.scroll.boton.y = MIN_Y;
				} else if (this.scroll.boton.y > MAX_Y) {
					this.scroll.boton.y = MAX_Y;
				}
				this.dispatchEvent(new ScrollEvent(ScrollEvent.POINT_SELECTED, {porcentaje:(1-(this.scroll.boton.y / MAX_Y))}));
			}
		}
		private function downBoton(event:MouseEvent):void {
			var point:Point = localToGlobal(new Point(event.currentTarget.mouseX, event.currentTarget.mouseY));
			
			if (this.scroll.boton.hitTestPoint(point.x,point.y)){
				this.mover = true;
			}
		}
		private function upBoton(event:MouseEvent):void {
			this.mover = false;
		}
		private function outBoton(event:MouseEvent):void {
			this.visible = false;
		}
	}
}